/*
 * @Description: 功能按钮
 * @Author: Zzt
 * @Date: 2023-01-07 10:03:23
 * @LastEditTime: 2023-02-10 20:09:22
 */
import { Button, Space } from 'antd';
import cs from 'classnames';
import { useEffect, useMemo, useState } from 'react';
import { useDetectionTemplateContext } from '../contexts/DetectionTemplateContext';
import TemplateConfiguration from './DetectionTemplate';

const PageOperate = (props: any) => {
  const { classname, archiveTypeList } = props;
  const { selectItems, deleteTemplateFunc, selectAT, selectFond, detectionType } =
    useDetectionTemplateContext();
  const [createVisible, setCreateVisible] = useState(false);
  const [archiveAndDetection, setArchiveAndDetection] = useState({});
  console.log('selsect', selectAT, selectFond);

  const onPerform = () => {
    deleteTemplateFunc(selectItems, `确定删除所选${selectItems.length}项检测模板？`);
  };

  useEffect(() => {
    if (selectAT.id) {
      setArchiveAndDetection({ archiveTypeId: selectAT.id, detectionType });
    }
  }, [selectAT, detectionType]);
  return (
    <>
      <div className={cs('filter-container', 'page-operate', classname)}>
        <div></div>
        <Space size="small">
          <Button
            onClick={() => {
              setCreateVisible(true);
            }}
          >
            新增模板
          </Button>
          {/* 
          {selectItems.length === 1 ? (
            <Button
            // onClick={() => {
            //   onChange();
            // }}
            >
              修改
            </Button>
          ) : (
            <Button disabled>修改</Button>
          )} */}
          {selectItems.length > 0 ? (
            <Button onClick={onPerform}>删除</Button>
          ) : (
            <Button disabled>删除</Button>
          )}
        </Space>
      </div>
      {/* 检测任务弹窗 */}
      {useMemo(
        () => (
          <TemplateConfiguration
            visible={createVisible}
            onClose={() => setCreateVisible(false)}
            ArchiveAndDetection={archiveAndDetection}
            fileData={''}
            archiveTypeList={archiveTypeList}
          />
        ),
        [createVisible]
      )}
    </>
  );
};
export default PageOperate;
